Skip to content

Make the range function work with integers#365

Merged
hunner merged 3 commits intopuppetlabs:masterfrom
dalen:range-integers
Nov 13, 2014
Merged

Make the range function work with integers#365
hunner merged 3 commits intopuppetlabs:masterfrom
dalen:range-integers

Conversation

@dalen
Copy link
Copy Markdown

@dalen dalen commented Nov 12, 2014

This is needed for the future parser which actually treats numbers as
numbers and strings as strings. With this patch you can use range(1,5)
instead of having to quote them like range('1','5').

Build on #364 which is just a style fix.

Erik Dalén added 2 commits November 12, 2014 15:52
This is needed for the future parser which actually treats numbers as
numbers and strings as strings. With this patch you can use range(1,5)
instead of having to quote them like range('1','5').
@daenney
Copy link
Copy Markdown

daenney commented Nov 12, 2014

👍

@igalic
Copy link
Copy Markdown
Contributor

igalic commented Nov 12, 2014

nice

@jhoblitt
Copy link
Copy Markdown

I'd suggest adding coverage of a 3 parameters call with all integers.

As the function stands now, range([1,"10"]) would return a list of integers and range(["1",10]) would return a list of strings. I think it would probably be less surprising if mixed type parameters resulted in an exception.

@dalen
Copy link
Copy Markdown
Author

dalen commented Nov 12, 2014

I'll add more tests, but actually both range(1,"10") and range("1",10) return a list of integers.

Stuff like range('a', 10) return an empty array, just like range('a', '10') also did

@jhoblitt
Copy link
Copy Markdown

hmmm. I'm not sure why that's the behavior.

2.1.0 :001 > (1.to_i .. "10".to_i).step(1).collect { |i| i }
 => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 

@dalen
Copy link
Copy Markdown
Author

dalen commented Nov 13, 2014

Not sure about which behavior?

On Wed, 12 Nov 2014 18:28 Joshua Hoblitt notifications@github.com wrote:

hmmm. I'm not sure why that's the behavior.

2.1.0 :001 > (1.to_i .. "10".to_i).step(1).collect { |i| i }
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]


Reply to this email directly or view it on GitHub
#365 (comment)
.

hunner added a commit that referenced this pull request Nov 13, 2014
Make the range function work with integers
@hunner hunner merged commit b6830f1 into puppetlabs:master Nov 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants